package com.starview.star.operators.arith.runtime;

import com.starview.platform.data.EvaluationException;
import com.starview.platform.data.IFunction;
import com.starview.platform.data.IValue;
import com.starview.platform.data.type.IType;
import com.starview.platform.data.type.StandardTypes;
import com.starview.platform.data.type.TypeUtils;
import com.starview.platform.data.value.BoolWrap;
import com.starview.platform.data.value.Factory;
import com.starview.star.operators.CafeEnter;



public abstract class BoolCompare
{
  private static final IType rawBoolType = StandardTypes.rawBoolType;

  public static class BoolEQ implements IFunction
  {
    @CafeEnter
    public static BoolWrap enter(boolean ix1, boolean ix2)
    {
      return Factory.newBool(ix1 == ix2);
    }

    @Override
    public IType getType()
    {
      return TypeUtils.functionType(rawBoolType, rawBoolType, StandardTypes.booleanType);
    }

    @Override
    public IValue enter(IValue... args) throws EvaluationException
    {
      return enter(Factory.boolValue(args[0]), Factory.boolValue(args[1]));
    }
  }

  public static class BoolNE implements IFunction
  {
    @CafeEnter
    public static BoolWrap enter(boolean ix1, boolean ix2)
    {
      return Factory.newBool(ix1 != ix2);
    }

    @Override
    public IType getType()
    {
      return TypeUtils.functionType(rawBoolType, rawBoolType, StandardTypes.booleanType);
    }

    @Override
    public IValue enter(IValue... args) throws EvaluationException
    {
      return enter(Factory.boolValue(args[0]), Factory.boolValue(args[1]));
    }
  }

  public static class BoolLE implements IFunction
  {
    @CafeEnter
    public static BoolWrap enter(boolean ix1, boolean ix2)
    {
      return Factory.newBool(ix1 ? ix2 : true); // ix1<=ix2
    }

    @Override
    public IType getType()
    {
      return TypeUtils.functionType(rawBoolType, rawBoolType, StandardTypes.booleanType);
    }

    @Override
    public IValue enter(IValue... args) throws EvaluationException
    {
      return enter(Factory.boolValue(args[0]), Factory.boolValue(args[1]));
    }
  }

  public static class BoolLT implements IFunction
  {
    @CafeEnter
    public static BoolWrap enter(boolean ix1, boolean ix2)
    {
      return Factory.newBool(ix1 ? false : ix2); // ix1<ix2
    }

    @Override
    public IType getType()
    {
      return TypeUtils.functionType(rawBoolType, rawBoolType, StandardTypes.booleanType);
    }

    @Override
    public IValue enter(IValue... args) throws EvaluationException
    {
      return enter(Factory.boolValue(args[0]), Factory.boolValue(args[1]));
    }
  }

  public static class BoolGT implements IFunction
  {
    @CafeEnter
    public static BoolWrap enter(boolean ix1, boolean ix2)
    {
      return Factory.newBool(ix1 ? ix2 : false);// ix1>ix2
    }

    @Override
    public IType getType()
    {
      return TypeUtils.functionType(rawBoolType, rawBoolType, StandardTypes.booleanType);
    }

    @Override
    public IValue enter(IValue... args) throws EvaluationException
    {
      return enter(Factory.boolValue(args[0]), Factory.boolValue(args[1]));
    }
  }

  public static class BoolGE implements IFunction
  {
    @CafeEnter
    public BoolWrap enter(boolean ix1, boolean ix2)
    {
      return Factory.newBool(ix1 ? true : ix2); // ix1>=ix2
    }

    @Override
    public IType getType()
    {
      return TypeUtils.functionType(rawBoolType, rawBoolType, StandardTypes.booleanType);
    }

    @Override
    public IValue enter(IValue... args) throws EvaluationException
    {
      return enter(Factory.boolValue(args[0]), Factory.boolValue(args[1]));
    }
  }
}
